<html><body>
    <?php
       //skapa en fil och skriva över den:
       $myFile = "userData.txt";
       $fh = fopen($myFile, 'w');

       //ta fram saker från POST och parsa in de:
       $username = $_POST['username'];
       $password = $_POST['password'];
       $can = implode(', ', $_POST['can']);
       $best = $_POST['bestLanguage'];
       $trev = $_POST['trevligste'];


       //skriva ut allt
       echo "your username: ". $username ."<br>";
       echo "your password: ". $password ."<br>";
       echo "language that you can: ". $can ."<br>";
       echo "best language: ". $best ."<br>";
       echo "preferred language: ". $trev ."<br>";

       //spara allt i filen //ist spara saker i databas : alex
       fwrite($fh, "your username: ". $username) ."\r\n";
       fwrite($fh, "your password: ". $password ."\r\n");
       fwrite($fh, "languages you can: ". $can ."\r\n");
       fwrite($fh, "best language: ". $best ."\r\n");
       fwrite($fh, "preferred language: ". $trev ."\r\n");
       fclose($fh);

       echo "file written and closed<br>";


       //testar cookies i php:
       //kolla om det finns en cookie:
       if(isset($_COOKIE['lastVisit']))
       {
       //spara dess data
       $visit = $_COOKIE['lastVisit']; 
       //skriva ut innehålet i cookie:
       echo "Your last visit was - ". $visit ."<br>";
       }
       else
       {
       //annars skriva att inga cookies finns:
       echo "You've got some stale cookies!";
       }


       //ska skriva när man senast besökte sidan om det hände senaste 60 dagar
       //cookie går ut om 60 dagar, räkna ut tiden genom att:
       //seconds * minutes * hours * days + current time
       $inTwoMonths = 60 * 60 * 24 * 60 + time(); 
       setcookie('lastVisit', date("G:i - m/d/y"), $inTwoMonths); 

       ?>
</body></html>


